#![allow(dead_code)]

struct MatchLrn {}

impl MatchLrn {
    pub fn hello() {
        println!("Match learning!");
    }
}

#[cfg(test)]
mod tests {

    #[test]
    #[allow(clippy::unnecessary_literal_unwrap)]
    fn basic_match_test() {
        let opt = Option::None::<usize>; // same as `let opt: Option<usize> = None;`
        let x = opt.unwrap_or_default();
        assert_eq!(x, 0);
    }

    #[test]
    fn match_struct_test() {
        struct Point {
            x: i32,
            y: i32,
        }

        let p = Point { x: 0, y: 7 };
        let Point { x, y } = p;
        assert_eq!(x, 0);
        assert_eq!(y, 7);
    }

    #[test]
    fn destruction_test() {
        struct Point {
            x: i32,
            y: i32,
        }
        let ((feet, inches), Point { x, y }) = ((3, 10), Point { x: 3, y: -10 });

        assert_eq!(feet, 3);
        assert_eq!(inches, 10);
        assert_eq!(x, 3);
        assert_eq!(y, -10);
    }

    #[test]
    fn ignore_parameter_test() {
        foo(3, 4);

        fn foo(_: i32, y: i32) {
            println!("This code only uses the y parameter: {}", y);
        }
    }

    #[test]
    // NOTE: 切片解构
    fn range_test() {
        let numbers = (2, 4, 8, 16, 32);

        let (first, .., last) = numbers;
        println!("Some numbers: {}, {}", first, last);
    }
}
